import sys
from System import Array, Type

import clr
clr.AddReference('Microsoft.VisualBasic')

class ActiveXObject(object):
    def __init__(self, object):
         self.target = object
    def __call__(self, member, *args):
        """Makes a late-bound call on the COM object.
        
        For properties, you need to prefix the member with 'get' or 'set'.
        In other words, if the property on the COM object is called 'Visible'
        and you want to get its value, then pass in 'getVisible' for the
        member argument. Likewise, to set the property value, pass in 
        'setVisible' for the member argument. The prefix is case-sensitive.
        """
        from Microsoft.VisualBasic.CompilerServices import NewLateBinding
        args = Array[object](args)
        if len(member) > 3:
            modifier = member[0:3]
            if modifier == 'get':
                return NewLateBinding.LateGet(self.target, None, member[3:], args, None, None, None)
            elif modifier == 'set':
                return NewLateBinding.LateSet(self.target, None, member[3:], args, None, None)
        return NewLateBinding.LateCall(self.target, None, member, args, None, None, None, False)

    def __getattribute__(self, name):
        try:
            return super(ActiveXObject, self).__getattribute__(name)
        except AttributeError:
            return lambda *args: self(name, *args)
